<?php
	class Chitietphieudat_model extends CI_Model 
	{
	    function LayChiTiet_LoaiGiuong($mapd) 
		{
        	$this->db->select('*');
	        $this->db->from('ChiTietPhieuDat');
    	    $this->db->join('LoaiGiuong', 'ChiTietPhieuDat.LoaiGiuong = LoaiGiuong.MaLG');
        	$this->db->where('ChiTietPhieuDat.PhieuDatPhong', $mapd);
	        $this->db->order_by('ChiTietPhieuDat.MaCT', 'asc');
    	    $query = $this->db->get();
        	if ($query->num_rows() > 0) 
			{
            	foreach ($query->result() as $row) 
				{
                	$data[] = $row;
	            }
    	        return $data;
        	}
	        return NULL;
    	}

	    function add_records_chitietdatphong($data) 
		{
        	$this->db->insert('ChiTietPhieuDat', $data);
	        return;
    	}

	    function LayChiTiet($mapd) 
		{
        	$this->db->select('*');
	        $this->db->from('ChiTietPhieuDat');
    	    $this->db->where('ChiTietPhieuDat.PhieuDatPhong', $mapd);
        	$query = $this->db->get();
	        if ($query->num_rows() > 0) 
			{
            	foreach ($query->result() as $row) 
				{
                	$data[] = $row;
	            }
    	        return $data;
        	}
	        return NULL;
    	}

	    function CapNhat($data, $mact) 
		{
        	$this->db->update('ChiTietPhieuDat', $data, array('MaCT' => $mact));
	        return $this->db->affected_rows();
    	}

	    function Xoa($mact) 
		{
        	return $this->db->delete('ChiTietPhieuDat', array('MaCT' => $mact));
	    }
	}
?>